﻿using System.Windows;
using System.Windows.Controls;


namespace 任务管理器
{


    /// <summary>
    /// 单任务模具.xaml 的交互逻辑
    /// </summary>
    public partial class 单任务模具 : UserControl
    {
        public delegate void 打开编辑窗委托(string 传入任务名称);
        public delegate void 直接完成任务(string 传入任务名称, bool 状态);
        public 打开编辑窗委托 打开编辑窗;
        public 直接完成任务 完成任务;

        public string 任务名 { get; set; } = "未设定任务名称";
        public int 进度条 { get; set; } = 0;
        public Visibility 是否展示进度条 { get; set; } = Visibility.Visible;
        public int? 唯一ID { get; set; } = 0;
        public bool 完成状态 { get; set; } = false;
        public int? 下级ID { get; set; } = 0;
        public string 任务详情 { get; set; } = "未设定任务详情";

        public void 进度条样式(进度条类型 类型)
        {

            进度.Style = this.Resources[类型.ToString()] as Style;

        }
        public enum 进度条类型
        {
            等待中,
            普通,
            进行中,
            错误
        }

        public 单任务模具()
        {
            InitializeComponent();
            任务名称.DataContext = this;
            进度.DataContext = this;
            完成框.DataContext = this;
            总成.DataContext = this;


        }

        private void 进度_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (是否展示进度条 == Visibility.Visible) { 进度条行高.Height = new GridLength(26, GridUnitType.Star); }
            if (是否展示进度条 == Visibility.Hidden || 是否展示进度条 == Visibility.Collapsed) { 进度条行高.Height = new GridLength(0, GridUnitType.Star); }
        }

        private void 打开编辑_Click(object sender, RoutedEventArgs e)
        {
            打开编辑窗(任务名);
        }

        private void 完成框_Checked(object sender, RoutedEventArgs e)
        {
            if (完成任务 != null)
            {
                完成任务(任务名, true);
            }

        }
    }
}
